import {reqCategoryList,reqGetBannerList,reqGetFloorList} from '@/api';
//home模块的小仓库
const state = {
    //state中数据默认初始值不能乱写，服务器返回对象/数组，需要根据接口返回值初始化
    categoryList: [],
    bannerList: [],
    floorList: [],
};
const actions = { 
    //通过API里面的接口函数调用，向服务器发送请求，获取服务器的数据
    async categoryList({commit}){//同步
        let result = await reqCategoryList();//等待请求获取结果
        if(result.code == 200){
            commit("CATEGORYLIST",result.data);
        }
    },
    //获取首页轮播图的数据
    async getBannerList({commit}){//同步
        let result = await reqGetBannerList();//等待请求获取结果
        if(result.code == 200){
            commit("BANNERLIST",result.data);
        }
    },
    //获取floor数据
    async getFloorList({commit}){//同步
        let result = await reqGetFloorList();//等待请求获取结果
        if(result.code == 200){
            commit("FLOORLIST",result.data);
        }
    }
};

const mutations = {
    CATEGORYLIST(state,categoryList){
        state.categoryList = categoryList;
    },
    BANNERLIST(state,bannerList){
        state.bannerList = bannerList;
    },
    FLOORLIST(state,floorList){
        state.floorList = floorList;
    }
};
const getters = {};
export default {
    state,
    actions,
    mutations,
    getters,
}